package ar.com.gestion.listeners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.table.TableModel;

import ar.com.gestion.springcontext.SpringContext;
import ar.com.gestion.tabla.ModeloTabla;
import ar.com.gestion.ventas.ModuloVentas;

public class BotonRefrescarTablaListener implements ActionListener {

	
	private ModuloVentas moduloVentas = (ModuloVentas) SpringContext.getContext()
			.getBean("moduloVentas");
	
	@Override
	public void actionPerformed(ActionEvent e) {
		
		DefaultListModel model= (DefaultListModel)moduloVentas.getLista().getModel();
		int tamanioLista = model.getSize();
		
		
		if (tamanioLista >0){
			
			if (JOptionPane.showConfirmDialog(new JFrame(),	"Si pulsa si, se anularan las ventas.", "Refrescar",JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION){
				
				moduloVentas.refresTabla();
				moduloVentas.refreshLista();
				moduloVentas.inicializarPrecioTotal();
				
				
			}
					
			
		}else{
			moduloVentas.refresTabla();
			
		}
		

	}

}
